package com.harmontronics.app.pedestal.db;

import com.blankj.utilcode.util.Utils;
import com.github.yuweiguocn.library.greendao.MigrationHelper;
import com.harmontronics.app.pedestal.db.model.DaoMaster;
import com.harmontronics.app.pedestal.db.model.LocalDataTableDao;

import org.greenrobot.greendao.database.Database;

public class LocalDataSQLiteOpenHelper extends DaoMaster.OpenHelper {

    public static final String DB_NAME = "hancode_base_config.db";

    public LocalDataSQLiteOpenHelper() {
        super(Utils.getApp(), DB_NAME, null);
    }

    @Override
    public void onUpgrade(Database db, int oldVersion, int newVersion) {
        super.onUpgrade(db, oldVersion, newVersion);
        MigrationHelper.migrate(db, new MigrationHelper.ReCreateAllTableListener() {
            @Override
            public void onCreateAllTables(Database db, boolean ifNotExists) {
                DaoMaster.createAllTables(db, ifNotExists);
            }

            @Override
            public void onDropAllTables(Database db, boolean ifExists) {
                DaoMaster.dropAllTables(db, ifExists);
            }
        }, LocalDataTableDao.class);

    }
}